<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="TS代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tsCode">
              <a-input v-model="model.tsCode" placeholder="请输入TS代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="股票代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="symbol">
              <a-input v-model="model.symbol" placeholder="请输入股票代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="股票名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <a-input v-model="model.name" placeholder="请输入股票名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="所在地域" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="area">
              <a-input v-model="model.area" placeholder="请输入所在地域"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="所属行业" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="industry">
              <a-input v-model="model.industry" placeholder="请输入所属行业"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="股票全称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fullname">
              <a-input v-model="model.fullname" placeholder="请输入股票全称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="英文全称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="enname">
              <a-input v-model="model.enname" placeholder="请输入英文全称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="拼音缩写" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cnspell">
              <a-input v-model="model.cnspell" placeholder="请输入拼音缩写"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="市场类型 （主板/中小板/创业板）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="market">
              <a-input v-model="model.market" placeholder="请输入市场类型 （主板/中小板/创业板）"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="交易所代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="exchange">
              <a-input v-model="model.exchange" placeholder="请输入交易所代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="交易货币" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currType">
              <a-input v-model="model.currType" placeholder="请输入交易货币"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="        上市状态： L上市 D退市 P暂停上市" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="listStatus">
              <a-input v-model="model.listStatus" placeholder="请输入        上市状态： L上市 D退市 P暂停上市"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="上市日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="listDate">
              <j-date placeholder="请选择上市日期" v-model="model.listDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="退市日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="delistDate">
              <j-date placeholder="请选择退市日期" v-model="model.delistDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="是否沪深港通标的，N否 H沪股通 S深股通" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isHs">
              <a-input v-model="model.isHs" placeholder="请输入是否沪深港通标的，N否 H沪股通 S深股通"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'StockBasicInfoForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           tsCode: [
              { required: true, message: '请输入TS代码!'},
           ],
           symbol: [
              { required: true, message: '请输入股票代码!'},
           ],
        },
        url: {
          add: "/stock/stockBasicInfo/add",
          edit: "/stock/stockBasicInfo/edit",
          queryById: "/stock/stockBasicInfo/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>